<?php

namespace app\admin\services;

use think\App;
use think\facade\Request;
use think\Service;
use think\facade\Session;
use app\admin\model\OperationModel;
use think\facade\Config;
class OperatlogService extends Service
{
    public function __construct(Request $request = null, App $app = null)
    {
        parent::__construct($request, $app);
           $this->OperationModel = new OperationModel();
    }

    /**
     * @param 登陆日志列表
     */
    public function userlist(){
        $post = Request::param();
        $page = isset($post['pageIndex'])?$post['pageIndex']:1;
        $limit = isset($post['pageSize'])?$post['pageSize']:10;
        if(!empty($post['username'])){
            $where = [['username','like','%'.$post['username'].'%']];
        }else{
            $where=[['frot','eq',1]];
        }
        $list = $this->OperationModel->userlist($where,$page,$limit);
        $counts = $this->OperationModel->county($where);
        $array = [];
        foreach ($list as $value){
            $value['actionTime'] = empty($value['actionTime'])?"":date("Y-m-d H:i:s",$value['actionTime']);
            $value['actionIp'] = empty($value['actionIp'])?"":$value['actionIp'];
            $array[] = $value;
        }
        if(empty($list)){
            $data['rel'] = false;
            $data['msg'] = "暂无数据";
        }else{
            $data['rel'] = true;
            $data['msg'] = "获取成功";
        }
        $data['list'] = $array;
        $data['count'] = $counts;
        return $data;
    }

    /**
     * @param $key
     * @param array $data
     * @return mixed
     */
    protected function _getResponse($key, $data = [])
    {
        $maps = [
            "SUCCESS" => ["status" => 0, "msg" => "sccuess", "data" => $data],
            "USER_ADD" => ["status" => 0, "msg" => "添加成功", "data" => $data],
            "ENBES_DATE" => ["status" => 0, "msg" => "操作成功", "data" => $data],
            "DELETE_DATE" => ["status" => 0, "msg" => "删除成功", "data" => $data],
            "PARAM_EORRE" => ["status" => 1, "msg" => "参数错误", "data" => $data],
            "NUKNOW_EORRE" => ["status" => 2, "msg" => "未知错误", "data" => $data],
            "DATA_ERROR" => ["status" => 7, "msg" => "数据不存在", "data" => $data],
            "AUTH_EORRE" => ["status" => 3, "msg" => "权限不足", "data" => $data],
            "NO_POST" => ["status" => 4, "msg" => "非法请求", "data" => $data],
            "USER_ERROR" => ["status" => 5, "msg" => "用户名已存在", "data" => $data],
            "CAOZUO_ERROR" => ["status" => 6, "msg" => "操作失败", "data" => $data],
            "EDIT_SUCCESS" => ["status" => 0, "msg" => "修改成功", "data" => $data],
            "CONFIRM_SUCCESS" => ["status" => 0, "msg" => "确认成功", "data" => $data],
            "EMLIE_SUCCESS" => ["status" => 0, "msg" => "留言成功", "data" => $data]
        ];
        return $maps[$key];
    }
}